<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <title>WIFI信息展示</title>
        
        <link rel="stylesheet" type="text/css" href="../css/cm-default.css"  />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/Aqua/css/ligerui-all.css" />
        <link rel="stylesheet" type="text/css" href="../ligerUI/skins/ligerui-icons.css" />
        <script src="../js/jquery-min.js" type="text/javascript"></script>
        <script src="../ligerUI/js/ligerui.min.js" type="text/javascript"></script>
        <script src="../js/common.js" type="text/javascript"></script>
        <script src="../js/json2.js" type="text/javascript"></script>
        <script type="text/javascript" src="../js/md5.js"></script>
        <script src="../js/validate/jquery.validate.js" type="text/javascript"></script>
        <script src="../js/validate/jquery.metadata.js" type="text/javascript"></script>
        <script src="../js/validate/messages_zh.js" type="text/javascript"></script>
        <script type="text/javascript">
            var defGrid,Wifi_Useable,shop_No,addDialog;
            var wifiNo;
            $(function(){
                $("#layout_main").ligerLayout({
                });

                defGrid = $("#query_list").ligerGrid({
                    columns:[
                        {display:'WIFI编号',name:'wifi_no',width:120,minWidth:60,align:'left'},
                        {display:'WIFI名称（ssid）',name:'wifi_ssid',width:120,minWidth:60,align:'left'},
                        {display:'商户编号',name:'shop_no',width:120,minWidth:60,align:'left'},
                        {display:'商户名称',name:'shop_name',width:120,minWidth:60,align:'left'},
                        {display:'WIFI密码',name:'wifi_pwd',width:120,minWidth:60,align:'left',render:function(rowdata,rowindex,value){
                            return "<a href='javascript:void(0);' class='opt-link' onclick='open_Modfiy_PW(" + rowindex + ")'>重置密码</a>";}},
                        {display:'密码是否有效',name:'wifi_useable',width:100,data:getStatus,render:switcher},
                        {display:'WIFI经度',name:'wifi_longitude',width:200,minWidth:60,align:'left'},
                        {display:'WIFI纬度',name:'wifi_latitude',width:200,minWidth:60,align:'left'},
                    ],
                    pageSize:10,
                    usePager: true,
                    sortName:'id',            
                    dataAction:'server',
                    url: '../common/q.jsp',                     
                    width:'100%',
                    height:'99%',
                    checkbox:false,
                    rownumbers:false,
                    fixedCellHeight:false,
                    colDraggable:true,
                    enabledEdit:true,
                    clickToEdit:false,
                    onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
                    onReload: toQuery,
                    onToFirst: function(item) {
                        toQuery(item, 1);
                    },
                    onToLast: function(item) {
                        var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
                        if (defGrid.options.total % defGrid.options.pageSize > 0)
                            p += 1;
                        toQuery(item, p);
                    },
                    onToPrev: function(item) {
                        var p = parseInt(defGrid.options.page);
                        if (p > 1)
                            p -= 1;
                        else
                            return;
                        toQuery(item, p);
                    },
                    onToNext: function(item) {
                        var p = parseInt(defGrid.options.total / defGrid.options.pageSize);
                        if (defGrid.options.total % defGrid.options.pageSize > 0)
                            p += 1;
                        var cp = parseInt(defGrid.options.page); 
                        if (cp < p)
                            cp += 1;
                        toQuery(item, cp);
                    }
                });
                appendAddBtn(openDictDef, "添加WIFI信息");
                appendModifyBtn(openModify, "修改WIFI信息");
                appendDeleteBtn(deleteRow, "删除WIFI信息");
                $("#pageloading").hide();
                //默认查询全部数据 
                toQuery();
            });

            //密码是否有效
            function switcher(item) {
                return paramRender(item, 'rbac.status', item.wifi_useable);
            }
            function shop_list(item) {
                return paramRender(item, 'shop_list', item.wifi_useable);
            }
             var getshop_list= new function () {
                 return getData('shop_list');
             }
            //密码状态获取
            var getStatus = new function () {
                return getData('rbac.status');
            }
            //查询
            function toQuery(item, page, pageSize) {
                if (!page)
                    page = defGrid.options.page;
                if (!pageSize)
                    pageSize = defGrid.options.pageSize;
                
                var param = new Object();
                param.wifi_ssid = $("#wifi_ssidS").val();
                param.shop_name = $("#shop_names").val();
                var data = JSON.stringify(reqObj('q','wifi.select.wifi_basic_info.query',JSON.stringify(param),'l',true,page,pageSize));
                ajaxSubmit("/cmwifi/rbac/cm.do?m=q", data, function(data) {
                    var d = data['data'].Rows;
                    var ps = defGrid.options.pageSize, p = defGrid.options.page, t = parseInt(data['data'].Total);
                    if (t > ps) {
                        for (var i = 0; i < (p - 1) * ps; i++) {
                            d.unshift(null);
                        }
                    }
                    defGrid.data = data['data'];
                    defGrid.set({data: data['data']});
                });
            }
             
            function openDictDef() {
                addDialog = $.ligerDialog.open({height:350,width:600,isResize:true,url:'./add_wifi_basic_info.html',title:'新增WIFI信息'});
                return false;
            }
            //编辑
            function openModify() {
                var row = defGrid.getSelectedRow();
                if (!row) {
                    $.ligerDialog.error('请先选择WIFI记录。','错误');
                    return;
                }
                modifyDialog = $.ligerDialog.open({height:400,width:600,isResize:true,url:'./add_wifi_basic_info.html?o=m&code='.concat(row.wifi_no),title:'修改WIFI信息'});
            }
            function deleteRow(rowid) {
                
                var row = defGrid.getSelectedRow();
                 if (!row) {
                   $.ligerDialog.error('请先选择要删除的WIFI记录。','错误');
                   return;
                  }                
                   $.ligerDialog.confirm('您确定要删除该项数据吗？', function(r) {
                       if (!r)
                           return;
                        toDel(JSON.stringify(row));
                       defGrid.deleteRow(rowid);
                   })
               }
            function toDel(row) {
                var param = JSON.stringify(reqObj('d','wifi.delete.wifi_basic_info.delete',row));
                   ajaxSubmit("/cmwifi/rbac/cm.do?m=d", param, function(data) {
                       if (data) {
                           if (parseInt(data['status']) > 0) {
                        	   toQuery();
                               $.ligerDialog.success('删除成功');
                           } else {
                               $.ligerDialog.error('删除失败');
                           }
                       }
                   });
           }
            //密码修改窗口
            function open_Modfiy_PW(rowid) {
            	wifiNo = defGrid.getRow(rowid)['wifi_no'];
                if (wifiNo) {
                    toReset('#new_dict_def input,select,textarea');
                    addDialog = $.ligerDialog.open({
                        target:$("#new_dict_def"),
                        title:"密码修改",
                        width:300,
                        height:200
                    });
                }
            }

            //修改密码时，两次密码一致性校验。不一致时，弹出窗口
            function toupdatepw()
            {  
                var pwd1=$("#password1").val();
                var pwd2=$("#password2").val();
                if(pwd1!=pwd2)
                {
                    $.ligerDialog.success('两次密码不一致请重新输入！');
                    return;
                }
                var parampw = new Object();
                parampw.wifi_no=wifiNo;
                parampw.wifi_pwd =pwd1;
                var param = JSON.stringify(reqObj('u','wifi.update.wifi_basic_info.update_pwd',JSON.stringify(parampw)));
                ajaxSubmit("/cmwifi/rbac/cm.do?m=u", param, function(data) {
                if (data) {
                    if (parseInt(data['status']) > 0) {
                        $.ligerDialog.success('保存成功');
                        addDialog.hide();
                    } else {
                        $.ligerDialog.error('保存失败');
                    }
                }
            });}
             
            
        </script>
        <style type="text/css">
            label{margin: 5px 20px 5px 15px;}
            .fields{height:35px;padding-top:5px;}
            .dict-info{width: 260px;padding: 10px;}
            .diff {margin:3px 0;}
            .lineD {width:99%;float:left;position:relative;overflow:hidden;margin:10px 0 2px 2px}
            .labelD {width:26%;position:relative;float:left;padding-top:3px;}
            .dplD {width:73%;position:relative;float:left;}
            .title{font-size:14px;font-weight:bold;background-position:left;padding-left:18px;}
        </style>
    </head>
    <body style="padding:0;">
        <div id="pageloading"></div>  
        <div id="layout_main">
            <div position="center" id="a_center" title="菜单列表">
                <div id="query_cond" class="fields">
                    <label>WIFI名称</label><input type="text" class="s-text txt-def" id="wifi_ssidS" />
                    <label>商户名称</label><input type="text" class="s-text txt-def" id="shop_names" />
                    <input type="button" value="查询" style="margin-left:25px;" onclick="toQuery();" />
                    <input type="button" value="清空" onclick="toReset('#query_cond input,select,textarea');" />
                </div>
                <div id="query_list"></div>
            </div>
        </div>
        <div id="new_dict_def" style="display:none;overflow:hidden;">
            <div class="line-div">
                <div class="labelD"><label>新密码</label></div>
                <div class="dplD"><input type="password" class="s-text txt-def" id="password1" /></div>
            </div>
        <div class="line-div">
                <div class="labelD"><label>确认密码</label></div>
                <div class="dplD"><input type="password" class="s-text txt-def" id="password2" /></div>
            </div>
            <div class="line-div" style="margin-top:15px;padding-left:30%;">
                <input type="button" value="保存" onclick="toupdatepw();" />
                <input type="button" value="清空" onclick="toReset('#new_dict_def input,select,textarea')" />
            </div>
           
        </div>
        
    </body>
</html>